<?php
/*
* Author：鑫宇工作室
* QQ：639519801
* url：www.xinyuream.com
*/

function admin_pass(){
	$user=admin_check();
//    echo pwdMd5("123123");exit;
	$old_password=pwdMd5(input('old_password'));
	$new_password=pwdMd5(input('new_password'));
	$again_password=pwdMd5(input('again_password'));
	if($new_password !=$again_password){
		json(array('code'=>201,'msg'=>'两次新密码不一致'));
	}
	if($old_password !=$user['password']){
		json(array('code'=>201,'msg'=>'旧密码错误'));
	}
        $res = \model\AdminModel::getInstance(1)->update(['username'=>$user['username']],['password'=>$new_password]);
	json(array('code'=>200,'msg'=>'修改成功'));
}

function admin_editapp(){
    $id=input('id');
    $appname=input('appname');
    $version=input('version');
    $status=input('status');
    $newurl=input('newurl');
    $new_notice=input('new_notice');

    $res = \model\AppModel::getInstance(1)->find(['id'=>$id]);
    if(!$res){
        json(['code'=>201,'msg'=>'App软件不存在']);
    }
    $data = [
        'appname'=>$appname,
        'version'=>$version,
        'status'=>$status,
        'newurl'=>$newurl,
        'new_notice'=>$new_notice,
    ];

//    if($newurl){
//        $data['size'] = getWebFileSize($newurl);
//    }

    \model\AppModel::getInstance()->update(['id'=>$id],$data);
    json(array('code'=>200,'msg'=>'修改成功'));

}

/**
 * 文件上传
 * @return void
 */
function admin_appAdd(){
    include_once APP.'func/upload.php';
    $appid =input('appid');
    $filename = input('filename');
    $upObj = new upload();
    $res = $upObj->add($appid,$filename);
//    echo $res;
    if($res && strlen($res)>0){
        json(['code'=>200,'msg'=>'上传成功','data'=>$res]);
    }else{
        json(['code'=>201,'msg'=>$upObj->getErr()]);
    }
}

function admin_system(){
	$user=admin_check();
	$arr=array('regopen','lockcode','dklogin','regzs','affzs','vcodelogin','locktime');
	foreach($arr as $v){
		$sql="update xy_config set svalue='".input($v)."' where skey='{$v}'";
		query($sql,2);
	}
	insertlog($user['username'],'修改系统设置');
	json(array('code'=>200,'msg'=>'保存成功'));
}

function admin_delwaf(){
	$user=admin_check();
	$ids=input('ids');
	$arr=explode("|",$ids);
	if(count($arr)<1){
		json(array('code'=>201,'msg'=>'请选择要删除IP'));
	}
	for($i=0;$i<count($arr);$i++){
		$id=intval($arr[$i]);
		$re=query("select ip from lock_ip_wfa where id='{$id}'");
		if($re){
			query("delete from lock_ip_wfa where id='{$id}'",2);
			insertlog($user['username'],'删除封锁IP：'.$re[0]['ip']);
		}
	}
	json(array('code'=>200,'msg'=>'删除完成'));
}
function admin_addwaf(){
	$user=admin_check();
	$ip=input('ip');
	if(preg_match('/^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1 -9]?\d))))$/',$ip) && strlen($ip)<=15){
		$sql="select * from lock_ip_wfa where ip='{$ip}'";
		$re=query($sql);
		if($re){
			json(array('code'=>201,'msg'=>'此IP已存在'));
		}
		query("insert into lock_ip_wfa(`ip`,`time`,`url`)value('{$ip}',now(),'管理添加')",2);
		insertlog($user['username'],'封锁IP：'.$ip);
		json(array('code'=>200,'msg'=>'添加成功'));
	}else{
		json(array('code'=>201,'msg'=>'请输入正确的IP'));
	}
	
}

function admin_waf(){
	admin_check();
	$page=1;
	$limit=config('limit');
	if(intval(input('page'))>1){
		$page=intval(input('page'));
	}
	if(intval(input('limit'))>$limit){
		$limit=intval(input('limit'));
	}
	$ip=input('ip');
	$where='';
	if($ip !=''){
		$where .=" where ip='{$ip}'";
	}
	$sql="select count(id) as count from lock_ip_wfa {$where}";
	$re=query($sql);
	$count=intval($re[0]['count']);
	$limit1=($page-1)*$limit;
	$sql="select id,ip,time as stime,url as rule from lock_ip_wfa {$where} order by id desc limit {$limit1},{$limit}";
	$re=query($sql);
	$arr=array(
		'code'=>200,
		'count'=>$count,
		'data'=>$re
	);
	json($arr);	
	
}

function admin_addnews(){
	$user=admin_check();
	$appid=intval(input('appid'));
	$content=input('content');
	$stime=input('stime');
	if($stime==''){
		$stime=date('Y-m-d H:i:s');
	}
	$re=query("select * from xy_app where id='{$appid}'");
	if(!$re){
		json(array('code'=>201,'msg'=>'APP不存在'));
	}
	$sql="insert into xy_news(`appid`,`content`,`stime`)value('{$appid}','{$content}','{$stime}')";
	query($sql,2);
	insertlog($user['username'],'添加公告');
	json(array('code'=>200,'msg'=>'添加成功'));
}

function admin_editnews(){
	$user=admin_check();
	$id=intval(input('id'));
	$appid=intval(input('appid'));
	$content=input('content');
	$re=query("select * from xy_news where id='{$id}'");
	if(!$re){
		json(array('code'=>201,'msg'=>'公告不存在'));
	}
	$re=query("select * from xy_app where id='{$appid}'");
	if(!$re){
		json(array('code'=>201,'msg'=>'APP不存在'));
	}
	$stime=input('stime');
	$set="set content='{$content}',appid='{$appid}'";
	if($stime!=''){
		$set="set content='{$content}',appid='{$appid}',stime='{$stime}'";
	}
	$sql="update xy_news {$set} where id='{$id}'";
	query($sql,2);
	insertlog($user['username'],'修改公告');
	json(array('code'=>200,'msg'=>'修改成功'));
}

function admin_delnews(){
	$user=admin_check();
	$ids=input('ids');
	$arr=explode("|",$ids);
	if(count($arr)<1){
		json(array('code'=>201,'msg'=>'请选择要删除的公告'));
	}
	for($i=0;$i<count($arr);$i++){
		$id=intval($arr[$i]);
		$re=query("select id from xy_news where id='{$id}'");
		if($re){
			query("delete from xy_news where id='{$id}'",2);
		}
	}
	insertlog($user['username'],'删除公告');
	json(array('code'=>200,'msg'=>'删除完成'));
	
}


function admin_news(){
	admin_check();
	$page=1;
	$limit=config('limit');
	if(intval(input('page'))>1){
		$page=intval(input('page'));
	}
	if(intval(input('limit'))>$limit){
		$limit=intval(input('limit'));
	}
	$appid=input('appid');
	$where="";
	if($appid>0){
		$where .=" where appid='{$appid}'";
	}
	$sql="select count(id) as count from xy_news {$where}";
	$re=query($sql);
	$count=intval($re[0]['count']);
	$limit1=($page-1)*$limit;
	$sql="select * from xy_news {$where} order by id desc limit {$limit1},{$limit}";
	$re=query($sql);
	$arr=array();
	for($i=0;$i<count($re);$i++){
		$rs=query("select appname from xy_app where id='{$re[$i]['appid']}'");
		if($rs){
			$re[$i]['appname']=$rs[0]['appname'];
		}else{
			$re[$i]['appname']='未知软件';
		}
		unset($re[$i]['appid']);
	}
	$arr=array(
		'code'=>200,
		'count'=>$count,
		'data'=>$re
	);
	json($arr);	
}

function admin_dellog(){
	admin_check();
	$ids=input('ids');
	$arr=explode("|",$ids);
	if(count($arr)<1){
		json(array('code'=>201,'msg'=>'请选择要删除的日志'));
	}
	for($i=0;$i<count($arr);$i++){
		$id=intval($arr[$i]);
		$re=query("select id from xy_log where id='{$id}'");
		if($re){
			query("delete from xy_log where id='{$id}'",2);
		}
	}
	json(array('code'=>200,'msg'=>'删除完成'));
	
	
}

function admin_log(){
	admin_check();
	$page=1;
	$limit=config('limit');
	if(intval(input('page'))>1){
		$page=intval(input('page'));
	}
	if(intval(input('limit'))>$limit){
		$limit=intval(input('limit'));
	}
	$sip=input('sip');
	$username=input('username');
	$where=" where 1=1";
	if($sip !=''){
		$where .=" and logip='{$sip}'";
	}
	if($username!=''){
		$where .=" and username='{$username}'";
	}
	$sql="select count(id) as count from xy_log {$where}";
	$re=query($sql);
	$count=intval($re[0]['count']);
	$limit1=($page-1)*$limit;
	$sql="select id,username,logip as ip,logtype as stype,logtime as stime,ipaddr from xy_log {$where} order by id desc limit {$limit1},{$limit}";
	$re=query($sql);
	$arr=array(
		'code'=>200,
		'count'=>$count,
		'data'=>$re
	);
	json($arr);	
}

function admin_addcard(){
	$user=admin_check();
	$stype=intval(input('stype'));
    $num=intval(input('setnum'));
    $info=input('info');
	for($i=0;$i<$num;$i++){
		$kami=pwdMd5(rand(1111,9999).uniqid().rand(1111,9999));
		query("insert into xy_card(`cardnum`,`stype`,`status`,`info`)value('{$kami}','{$stype}',1,'{$info}')",2);
	}
	insertlog($user['username'],'新增'.get_card_type($stype)." {$num} 张");
	json(array('code'=>200,'msg'=>'添加成功'));
}

function admin_delcard(){
	$user=admin_check();
	$ids=input('ids');
	$arr=explode("|",$ids);
	if(count($arr)<1){
		json(array('code'=>201,'msg'=>'请选择要删除的卡密'));
	}
	for($i=0;$i<count($arr);$i++){
		$id=intval($arr[$i]);
		$re=query("select cardnum from xy_card where id='{$id}'");
		if($re){
			insertlog($user['username'],'删除卡密：'.$re[0]['cardnum']);
			query("delete from xy_card where id='{$id}'",2);
		}
	}
	json(array('code'=>200,'msg'=>'删除完成'));
}

function admin_card(){
	admin_check();
	$page=1;
	$limit=config('limit');
	if(intval(input('page'))>1){
		$page=intval(input('page'));
	}
	if(intval(input('limit'))>$limit){
		$limit=intval(input('limit'));
	}
	$stype=intval(input('stype'));
	$status=intval(input('status'));
	$username=input('username');
	$where=" where 1=1";
	if($stype>0){
		$where .=" and stype='{$stype}'";
	}
	if($status>0){
		$where .=" and status='{$status}'";
	}
	if($username!=''){
		$where .=" and username='{$username}'";
	}
	$sql="select count(id) as count from xy_card {$where}";
	$re=query($sql);
	$count=intval($re[0]['count']);
	$limit1=($page-1)*$limit;
	$sql="select * from xy_card {$where} order by id desc limit {$limit1},{$limit}";
	$re=query($sql);
	for($i=0;$i<count($re);$i++){
		$re[$i]['stype']=get_card_type($re[$i]['stype']);
		$re[$i]['status']=$re[$i]['status']==2?'已使用':'未使用';
	}
	$arr=array(
		'code'=>200,
		'count'=>$count,
		'data'=>$re
	);
	json($arr);		
}

function admin_delapp(){
	$user=admin_check();
	$ids=input('ids');
	$arr=explode("|",$ids);
	if(count($arr)<1){
		json(array('code'=>201,'msg'=>'请选择要删除的APP'));
	}
	for($i=0;$i<count($arr);$i++){
		$id=intval($arr[$i]);
		if($id>0){
			$re=query("select appname from xy_app where id='{$id}'");
			if($re){
				insertlog($user['username'],'删除APP：'.$re[0]['appname']);
				del_app($id);
			}
		}
	}
	json(array('code'=>200,'msg'=>'APP删除成功'));
}

function del_app($id){
	query("delete from xy_app where id='{$id}'",2);
	query("delete from xy_news where appid='{$id}'",2);
	$re=query("select username from xy_user where appid='{$id}'");
	for($i=0;$i<count($re);$i++){
		del_user($re[$i]['username']);
	}
	return true;
}

function admin_addapp(){
	$user=admin_check();
	$appname=input('appname');	
	$version=input('version');	
	$status=intval(input('status'))==2?2:1;	
	if($appname=='' || $version==''){
		json(array('code'=>201,'msg'=>'请填写完整数据'));
	}
	query("insert into xy_app(`appname`,`version`,`status`)value('{$appname}','{$version}','{$status}')",2);
	insertlog($user['username'],'添加APP：'.$appname);
	json(array('code'=>200,'msg'=>'添加成功'));
}

function admin_setapp(){
	$user=admin_check();
	$status=intval(input('status'))==1?1:2;
	$id=intval(input('id'));
	$re=query("select appname from xy_app where id='{$id}'");
	if(!$re){
		json(array('code'=>201,'msg'=>'APP不存在'));
	}
	query("update xy_app set status='{$status}' where id='{$id}'",2);
	query("update xy_user set status='{$status}' where appid='{$id}'",2);
	insertlog($user['username'],($status===1?'启用':'禁用').'APP：'.$re[0]['appname']);
	json(array('code'=>200,'msg'=>($status===1?'启用成功':'禁用成功')));
}

function admin_app(){
	admin_check();
	$page=1;
	$limit=config('limit');
	if(intval(input('page'))>1){
		$page=intval(input('page'));
	}
	if(intval(input('limit'))>$limit){
		$limit=intval(input('limit'));
	}
	$status=intval(input('status'));
	$where=" where 1=1";
	if($status>0){
		$where .=" and status='{$status}'";
	}
	$sql="select count(id) as count from xy_app {$where}";
	$re=query($sql);
	$count=intval($re[0]['count']);
	$limit1=($page-1)*$limit;
	$sql="select * from xy_app {$where} order by id desc limit {$limit1},{$limit}";
	$re=query($sql);
	$ls=array();
	for($i=0;$i<count($re);$i++){
		$ls[$i]=$re[$i];
		$sql="select count(id) as count from xy_user where appid='{$ls[$i]['id']}'";
		$rs=query($sql);
		$ls[$i]['usernum']=$rs[0]['count'];
	}
	
	
	$arr=array(
		'code'=>200,
		'count'=>$count,
		'data'=>$ls
	);
	json($arr);
	
}

function admin_delmember(){
	$user=admin_check();
	$ids=input('ids');
	$arr=explode("|",$ids);
	if(count($arr)<1){
		json(array('code'=>201,'msg'=>'请选择要删除的账号'));
	}
	for($i=0;$i<count($arr);$i++){
		$id=intval($arr[$i]);
		if($id>0){
			$re=query("select username from xy_user where id='{$id}'");
			if($re){
				del_user($re[0]['username']);
			}
		}
	}
	
	json(array('code'=>200,'msg'=>'账号删除成功'));
}

function del_user($username){
	$user=admin_check();
	insertlog($user['username'],'删除账号：'.$username);
	query("delete from xy_user where username='{$username}'",2);
	query("delete from xy_log where username='{$username}'",2);
	query("delete from xy_card where username='{$username}'",2);
	return true;
}

function admin_editmember(){
	$user=admin_check();
	$username=input('username');
	$viptime=input('viptime');
	$vcode=input('vcode');
	$appid=intval(input('appid'));
    $id = intval(input('id'));
	$status=intval(input('status'))==2?2:1;
	if(!query("select * from xy_app where id='{$appid}'")){
		json(array('code'=>201,'msg'=>'软件ID不存在'));
	}
    $update = [
        'status'=>$status,
        'appid'=>$appid,
        'vcode'=>$vcode,
        'viptime'=>$viptime,
        'username'=>$username,
    ];
    \model\UserModel::getInstance(1)->update(['id'=>$id],$update);

	insertlog($user['username'],'修改账号：'.$username);
	json(array('code'=>200,'msg'=>'账号修改成功'));
}

function admin_addmember(){
	$user=admin_check();
	$username=input('username');
	$password=input('password');
	$viptime=input('viptime');
	$vcode=input('vcode');
	$appid=intval(input('appid'));
	$status=intval(input('status'))==2?2:1;
	if(strlen($username)<config('username')){
		json(array('code'=>201,'msg'=>'用户名不能小于6位'));
	}
	if(strlen($password)<config('password')){
		json(array('code'=>201,'msg'=>'密码不能小于6位'));
	}
	if(!query("select * from xy_app where id='{$appid}'")){
		json(array('code'=>201,'msg'=>'软件ID不存在'));
	}
	if(query("select * from xy_user where username='{$username}'")){
		json(array('code'=>201,'msg'=>'账号已存在'));
	}
	if($viptime==''){
		$viptime="0000-00-00 00:00:00";
	}
	$pass=pwdMd5($password);
	$sql="insert into xy_user(`username`,`password`,`appid`,`viptime`,`vcode`,`status`)value('{$username}','{$pass}','{$appid}','{$viptime}','{$vcode}','{$status}')";
	query($sql,2);
	insertlog($user['username'],'添加账号：'.$username);
	json(array('code'=>200,'msg'=>'添加成功'));
	
}

function admin_setstatus(){
	$user=admin_check();
	$status=intval(input('status'))==1?1:2;
	$id=intval(input('id'));
	$re=query("select username from xy_user where id='{$id}'");
	if(!$re){
		json(array('code'=>201,'msg'=>'账号不存在'));
	}
	query("update xy_user set status='{$status}' where id='{$id}'",2);
	insertlog($user['username'],($status==1?'启用账号：':'禁用账号：').$re[0]['username']);
	json(array('code'=>200,'msg'=>$status==1?'启用成功':'禁用成功'));
}

function admin_apps(){
	$sql="select * from xy_app";
	$re=query($sql);
	return $re;
}

function admin_tongji(){
	$arr=array();
	$re=query("select count(id) as count from xy_user");
	$arr['usernum']=intval($re[0]['count']);
	$re=query("select count(id) as count from xy_user where viptime>now()");
	$arr['vipnum']=intval($re[0]['count']);
	$re=query("select count(id) as count from xy_card");
	$arr['cardnum']=intval($re[0]['count']);
	$re=query("select count(id) as count from xy_card where status=1");
	$arr['card1']=intval($re[0]['count']);
	$re=query("select count(id) as count from xy_card where status=2");
	$arr['card2']=intval($re[0]['count']);
	$re=query("select count(id) as count from xy_app");
	$arr['appnum']=intval($re[0]['count']);
	return $arr;
}

function admin_member(){
	admin_check();
	$page=1;
	$limit=config('limit');
	if(intval(input('page'))>1){
		$page=intval(input('page'));
	}
	if(intval(input('limit'))>$limit){
		$limit=intval(input('limit'));
	}
	$app=intval(input('app'));
	$status=intval(input('status'));
	$username=input('username');
	$kami = input('kami');
	$viptime=intval(input('viptime'));
	$where=" where 1=1";
	if($app>0){
		$where .=" and appid='{$app}'";
	}
	if($status>0){
		$where .=" and status='{$status}'";
	}
	if($username!=''){
		$where .=" and username='{$username}'";
	}
	if($kami!=''){
        $res = \model\CardModel::getInstance(1)->find(['cardnum'=>$kami]);
        if($res && $res['username']){
            $where.= " and id = {$res['username']}";
        }else{
            $where = 'where 1=2 ';
        }
	}

	if($viptime>0){
		if($viptime==1){
			$where .=" and viptime>=now()";
		}else{
			$where .=" and viptime<now()";
		}
	}
	
	$sql="select count(id) as count from xy_user {$where}";
	$re=query($sql);
	$count=intval($re[0]['count']);
	$limit1=($page-1)*$limit;
    // vcode,
	$sql="select id,username,loginip,logintime,onlinetime,regtime,appid as appname,status,if(viptime>now(),viptime,'已过期') as viptime from xy_user {$where} order by id desc limit {$limit1},{$limit}";
	$re=query($sql);
	$ls=array();
	for($i=0;$i<count($re);$i++){
		$ls[$i]=$re[$i];
		$sql="select * from xy_app where id='{$ls[$i]['appname']}'";
		$rs=query($sql);
		if(!$rs){
			$ls[$i]['appname']='未知软件';
		}else{
			$ls[$i]['appname']=$rs[0]['appname'];
		}
        $ls[$i]['logintime'] = getDateText(strtotime($ls[$i]['logintime']));
        $ls[$i]['onlinetime'] = getDateText(strtotime($ls[$i]['onlinetime']));
        $ls[$i]['loginip'] = join(' ',\ip\Ip::find($ls[$i]['loginip']));
        if($ls[$i]['viptime']!='已过期'){
            $ls[$i]['viptime'] = getDateText($ls[$i]['viptime'],2);
        }

        $kami = \model\CardModel::getInstance(1)->find(['username'=>$ls[$i]['id']],'id,info','info desc,id desc');
        if($kami){
            $kami = $kami['info']?:'无备注';
        }else{
            $kami = '未购卡';
        }
        // 查询卡密备注
        $ls[$i]['kamistr'] = $kami;

	}
	
	
	$arr=array(
		'code'=>200,
		'count'=>$count,
		'data'=>$ls
	);
	json($arr);
	
	
}

function admin_info(){
	admin_check();
	$arr=array(
		'code'=>200,
		'data'=>array(
			'homeInfo'=>array('title'=>'首页','href'=>'manage/home'),
			'logoInfo'=>array('title'=>config('webname'),'image'=>'/images/logo.png','href'=>'/'),
			'menuInfo'=>array(
				array('title'=>'管理首页','icon'=>'fa fa-home','href'=>'manage/home','target'=>'_self'),
				array('title'=>'用户管理','icon'=>'fa fa-user','href'=>'manage/member','target'=>'_self'),
				array('title'=>'软件管理','icon'=>'fa fa-shield','href'=>'manage/app','target'=>'_self'),
				array('title'=>'卡密管理','icon'=>'fa fa-indent','href'=>'manage/card','target'=>'_self'),
				array('title'=>'公告管理','icon'=>'fa fa-file-text-o','href'=>'manage/news','target'=>'_self'),
				array('title'=>'日志查询','icon'=>'fa fa-clock-o','href'=>'manage/log','target'=>'_self'),
				array('title'=>'安全记录','icon'=>'fa fa-clock-o','href'=>'manage/waf','target'=>'_self'),
				array('title'=>'系统设置','icon'=>'fa fa-gears','href'=>'manage/system','target'=>'_self'),
			)
		)
	);
	json($arr);
	
}

function admin_check($bool=false){
	if(!isset($_SESSION['username']) || !isset($_SESSION['token'])){
		if($bool){
			echo "<script>window.location = '/manage/login';</script>";
			exit;
		}else{
			json(array('code'=>500,'msg'=>'登录已过期,请重新登录'));
		}
	}else{
		$sql="select * from xy_admin where username='{$_SESSION['username']}'";
		$re=query($sql);
		if(!$re || $re[0]['token'] != $_SESSION['token']){
			if($bool){
				echo "<script>window.location = '/manage/login';</script>";
				exit;
			}else{
				json(array('code'=>500,'msg'=>'登录已过期,请重新登录'));
			}
		}
		return $re[0];	
	}
}

function admin_login(){
	$arr=array();
	$vercode=xiaoxie(input('vercode'));
	$username=input('username');
	$password=input('password');
	if(false && $vercode != xiaoxie($_SESSION['code'])){
		$arr['code']=201;
		$arr['msg']='验证码错误';
	}else{
		if($username=='' || $password==''){
			$arr['code']=201;
			$arr['msg']='用户名或密码错误';
		}else{
			$pass=pwdMd5($password);
            $re = \model\AdminModel::getInstance(1)->find(['username'=>$username]);
			if(!$re){
				$arr['code']=201;
				$arr['msg']='账号不存在';
			}else if($re['password']!=$pass){
                $arr['code']=201;
                $arr['msg']='用户名或密码错误';
            }
            else{
                spAccess('w','adminlog_'.$re['id'],[
                    'login_ip'=>$re['login_ip'],
                    'last_time'=>$re['last_time'],
                ]);
				$token=pwdMd5(rand(1111,9999).uniqid().rand(1111,9999));
				$time=date('Y-m-d H:i:s');
				$ip=get_ip();
				$arr['code']=200;
				$arr['msg']='登录成功';
				$arr['data']=array('access_token'=>$token);
                \model\AdminModel::getInstance(1)->update(['id'=>$re['id']],[
                    'token'=>$token,
                    'last_time'=>$time,
                    'login_ip'=>$ip,
                ]);
                $_SESSION['admin_id']=$re['id'];
				$_SESSION['username']=$re['username'];
				$_SESSION['token']=$token;
                insertlog($username,'管理登录',$re['id']);

			}
		}
	}
	unset($_SESSION['code']);
	json($arr);
}
function admin_logout(){
	if(isset($_SESSION['username'])){
		unset($_SESSION['username']);
	}
	if(isset($_SESSION['token'])){
		unset($_SESSION['token']);
	}
	header("Location:/");
	exit;
}


?>